package com.martin.fast_frame_compose.page.refresh

import androidx.compose.runtime.mutableStateOf
import com.martin.fast_frame_compose.base.BaseViewModel
import com.martin.lib_base.bean.common.BaseResponse
import com.martin.lib_base.interfaces.IGetData
import com.martin.lib_base.model.PageModel
import dev.utils.app.HandlerUtils
import dev.utils.common.RandomUtils

class RefreshViewModel : BaseViewModel(), IGetData {

    val pageModel = PageModel(this)

    val boxRefreshing = mutableStateOf(false)


    override fun getData() {
        // 这里模拟网络请求
        HandlerUtils.postRunnable(
            {
                val response = BaseResponse<String>()
                response.rows = (0..10).map { RandomUtils.getRandomLetters(6) }.toList()
                response.total = Int.MAX_VALUE
                pageModel.handleData(response)
            }, 2000
        )
    }

    fun onBoxRefresh() {
        boxRefreshing.value = true
        HandlerUtils.postRunnable(
            {
                boxRefreshing.value = false
            }, 2000
        )
    }
}
